{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "a40b7e75-612f-4b2e-a68d-fbaeadc0668b",
   "metadata": {},
   "source": [
    "## 1. 列表定义"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "0bf11ab7-af54-426e-ac8f-d261f03dbe33",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1.71, 1.83, 1.79, 1.68]"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[1.71, 1.83, 1.79, 1.68]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1af4cd0a-3830-4efd-88a1-ee2a782e733e",
   "metadata": {},
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "ac5442bb-0843-4144-9f03-b7d339baa758",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[10, 1.23, 'ABC', True]"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[10, 1.23, 'ABC', True]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "715b8ee4-a65d-4eb5-83aa-f3753cb3120c",
   "metadata": {},
   "source": [
    "<br>\n",
    "空列表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "9b158c20-2e2d-469a-a3e0-6a13afa32149",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[]"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "94f1ba61-ab7d-4c78-bf57-2b3a11cda4f2",
   "metadata": {},
   "source": [
    "## 2. 访问列表中的项目(item)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "73038d61-942d-4ba4-aa2e-f5b121be17ac",
   "metadata": {},
   "outputs": [],
   "source": [
    "s = [10, 20, 30, 40, 50, 60]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "7348809b-e3f1-446d-a5b0-4c65b14cd672",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "20"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "ebffa6ac-3c4c-43ca-bf11-d15c62ac95de",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "60"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s[-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "aff5fc57-d86e-450f-b190-36926f38dbb7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[10, 30, 50]"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s[::2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "33cfc0fe-fad1-4811-856b-3e4417a49e76",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[60, 50, 40, 30, 20, 10]"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s[::-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "c1d68a70-3eb9-423e-9266-609df1e4195c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[10, 20, 30, 40, 50, 60]"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s[:]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9329a6e8-4819-47e3-a6cc-3d117bcd5393",
   "metadata": {},
   "source": [
    "## 3. 列表运算"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b75ca3af-5c53-4d5e-aded-5403284999bc",
   "metadata": {},
   "source": [
    "判断项目是否在列表内"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "bb2ca6a6-7326-4a79-b89f-b0d6b6147aa8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s = [10, 20, 30, 40]\n",
    "20 in s"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2ecd05d8-ee39-4cc5-80f4-0a22de8620a2",
   "metadata": {},
   "source": [
    "拼接列表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "f684ae8f-b501-44b9-bff9-2ea640e8c1fd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[10, 20, 30, 40, 50]"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[10, 20, 30] + [40, 50]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "265313e6-588a-4de7-941c-eab6c499fc4d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[10, 20, 30, 10, 20, 30, 10, 20, 30]"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[10, 20, 30] * 3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f2aae75a-5215-458a-bcd4-0f12306669ea",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "e6eb9165-0e27-4008-943d-2fb801e10203",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[10, 20, 30, 40]"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s = [10, 20, 30]\n",
    "s.append(40)\n",
    "s"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4743b9e7-2288-401c-b71c-ade640a5c307",
   "metadata": {},
   "source": [
    "扩展列表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "ab7479e0-58db-4036-9f05-24eb92ff487e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[10, 20, 30, 40, 50]"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s = [10, 20, 30]\n",
    "s.extend([40, 50])\n",
    "s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "e2156dd5-421d-425b-aa1c-7dead00714a2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[10, 20, 30, 40, 50]"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s = [10, 20, 30]\n",
    "s += [40, 50]\n",
    "s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "85ef1786-36e1-4d3f-ad1a-a6fc290d5ed2",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "d8d15e2c-baa3-4df7-9626-5d16ad3225cb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[10, 20, 30, 40]"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s = [10, 20, 30]\n",
    "s.append(40)\n",
    "s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "32c33b1d-8ef0-4c58-90f1-c3cadde09160",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "402f2800-04b5-46b9-b971-51e319af1fdb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[10, 20, 25, 30]"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s = [10, 20, 30]\n",
    "s.insert(2, 25)\n",
    "s"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "46ece00b-a8e3-4a50-bdb3-385f9eceee0c",
   "metadata": {},
   "source": [
    "<br>\n",
    "\n",
    "修改列表项目"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "0aa04a8f-cb82-49f1-aa79-5a589ff4d330",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[10, 25, 30]"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s = [10, 20, 30]\n",
    "s[1] = 25\n",
    "s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "0bf0d35a-3801-48c1-9ea3-34896748f535",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[10, 200, 30, 400, 50]"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s = [10, 20, 30, 40, 50]\n",
    "s[1:5:2] = [200, 400]\n",
    "s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7917b07a-5ad4-4b99-a36a-fc605c625dc2",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "c5910deb-a54c-4a1d-a5d9-1d28d948f879",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[10, 30]"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s = [10, 20, 30]\n",
    "del s[1]\n",
    "s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "35f6dcf3-cdcb-461c-acb0-7c1ded63f0e6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[10, 30, 50]"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s = [10, 20, 30, 40, 50]\n",
    "del s[1:5:2]\n",
    "s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d124b770-f5ea-4539-a051-43e7c1179f08",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "85a06a85-ce96-4f14-9f8a-8b3d4bcd6b21",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[10, 30, 20]"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s = [10, 20, 30, 20]\n",
    "s.remove(20)\n",
    "s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fb962a25-680b-492c-b5d0-5861d8c5f66d",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "4d659921-7a70-4921-986a-73c66f5fe055",
   "metadata": {},
   "outputs": [
    {
     "ename": "ValueError",
     "evalue": "list.remove(x): x not in list",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "Cell \u001b[0;32mIn[23], line 2\u001b[0m\n\u001b[1;32m      1\u001b[0m s \u001b[38;5;241m=\u001b[39m [\u001b[38;5;241m10\u001b[39m, \u001b[38;5;241m20\u001b[39m, \u001b[38;5;241m30\u001b[39m, \u001b[38;5;241m20\u001b[39m]\n\u001b[0;32m----> 2\u001b[0m \u001b[43ms\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mremove\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m50\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[1;32m      3\u001b[0m s\n",
      "\u001b[0;31mValueError\u001b[0m: list.remove(x): x not in list"
     ]
    }
   ],
   "source": [
    "s = [10, 20, 30, 20]\n",
    "s.remove(50)\n",
    "s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "dc046e9c-c9eb-43a5-bbcf-caa13039560c",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "f61b5448-78a1-4c3e-bac7-0fc9f3eb2957",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[]"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s = [10, 20, 30, 40, 50]\n",
    "s.clear()\n",
    "s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "860a6a56-ee46-483b-a2d3-905163583b30",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[]"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s = [10, 20, 30, 40, 50]\n",
    "del s[:]\n",
    "s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a67401fd-142d-4562-a105-bfbb24d26c47",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
